var express = require('express');
const { data } = require('jquery');
var router = express.Router();
const { get, addIndent, find, cinemas, getSc, usrse, findOne, getIall, addSeating, indentCur } = require('../api/indent');

/* GET home page. */

router.get('/', async function (req, res, next) {

  const data = await get()

  res.send(data)
});
//分页
/**,
 * @swagger
 * /indent:
 *    get:
 *      tags:
 *      - 订单管理模块          # 接口分类
 *      summary: 获取订单信息   # 接口备注
 *      description: 获取订单数据信息   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      parameters:
 *        - in: query
 *          name: curPage
 *          schema:
 *            type: integer
 *            default: 1
 *          required: true
 *          description: 当前页码
 *        - in: query
 *          name: eachPage
 *          schema:
 *            type: integer
 *            default: 10
 *          required: true
 *          description: 每页显示条数
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "获取成功"     # 返回 code 码描述
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/ArrayOfindent'
 *
 * */
router.get('/inCur', async function (req, res, next) {
  const { curPage, eachPage } = req.query;
  const data = await indentCur({ curPage, eachPage });
  res.send(data);
});
//查找用户
router.get('/users', async function (req, res, next) {
  const data = await usrse()
  res.send(data)
});
// 查找所有放映厅
router.get('/theaters/getAll', async function (req, res, next) {
  const data = await find()
  res.send(data)
});
//查找影院
router.get('/cinemas', async function (req, res, next) {
  const { curPage, eachPage } = req.query;
  const data = await cinemas({ curPage, eachPage });
  res.send(data)
});
//查找排片所有数据
router.get('/schedules', async function (req, res, next) {

  const data = await getSc();;
  res.send(data)
});

//查询订单数据
/**,
 * @swagger
 * /indent/getOne:
 *    get:
 *      tags:
 *      - 订单管理模块          # 接口分类
 *      summary: 通过用户名name获取用户信息查询订单数据   # 接口备注
 *      description: 用于通过name获取订单信息   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      requestBody:
 *        required: true
 *        content:
 *          application/json:
 *            schema:
 *              $ref: '#/components/schemas/indent/getOne'
 *            example:
 *              name: "11"
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "获取成功"     # 返回 code 码描述
 *          content:
 *            application/json:
 *              schema:
 *                $ref: '#/components/schemas/indent/getOne'
 *
 * */
router.get('/getOne', async function (req, res, next) {
  const { name } = req.query;
  const username = await findOne({ name })
  const usersNameId = username[0]._id
  const data = await getIall({ usersNameId })
  res.send(data)
});

//新增订单数据
/**
 * @swagger
 * /schedules/addData:
 *    post:
 *      tags:
 *      - 订单模块         # 接口分类
 *      summary: 新增订单接口   # 接口备注
 *      description: 新增订单接口   # 接口描述
 *      consumes:
 *      - "application/json"    # 接口接收参数类型
 *      responses:  # 响应
 *        200:     # http状态码
 *          description: "订单新增成功！！！" # 返回 true
 *          content:
 *            application/json:
 *              schema:
 *                name: 'true'
 * */
router.post('/add', async function (req, res, next) {
  const data = req.body;
  const datas = await addIndent(data)
  res.send(datas)
});


module.exports = router;